﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：BackOfCardInfo
// 文件功能描述：退卡销户
//
// 
// 创建标识：2012-02-21 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class BackOfCardInfo
    {
        /// <summary>
        /// 人员ID
        /// </summary>
        public int PID
        {
            get;
            set;
        }
        /// <summary>
        /// 人员编号
        /// </summary>
        public string EmpNo
        {
            get;
            set;
        }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string deptName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员类型(卡类型)
        /// </summary>
        public string PersonTypeName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员姓名
        /// </summary>
        public string PName
        {
            get;
            set;
        }
        /// <summary>
        /// 部门编号
        /// </summary>
        public int Dep_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 注销类型（1：有卡销户 2：无卡销户 3：自动离职）
        /// </summary>
        public int LOGOUTTYPE
        {
            get;
            set;
        }
        /// <summary>
        /// 卡序列号
        /// </summary>
        public Int64 CardSerial
        {
            get;
            set;
        }
        /// <summary>
        /// 卡状态
        /// </summary>
        public string Status
        {
            get;
            set;
        }
        /// <summary>
        /// 工作状态
        /// </summary>
        public string WorkStatus
        {
            get;
            set;
        }
        /// <summary>
        /// 消费余额
        /// </summary>
        public decimal Balance
        {
            get;
            set;
        }
        /// <summary>
        /// 押金
        /// </summary>
        public decimal CardOptDeposit
        {
            get;
            set;
        }
        /// <summary>
        /// 退消费余额
        /// </summary>
        public decimal BalanceBack
        {
            get;
            set;
        }
        /// <summary>
        /// 折旧费
        /// </summary>
        public decimal OldMoney
        {
            get;
            set;
        }
        /// <summary>
        /// 实退押金
        /// </summary>
        public decimal CardOptDepositBack
        {
            get;
            set;
        }
        /// <summary>
        /// 操作员
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }
        private DataAccessBackOfCard dar;
        private int BackOfCardcount;
        public int _BackOfCardcount
        {
            get { return BackOfCardcount; }
        }
        public BackOfCardInfo(bool isgetcount)
        {
            dar = new DataAccessBackOfCard();
            if (isgetcount)
            {
                BackOfCardcount = GetBackOfCardCount();
            }
        }
        public BackOfCardInfo()
        { }

        /// <summary>
        /// 获取已发卡的数量
        /// </summary>
        /// <returns></returns>
        private int GetBackOfCardCount()
        {
            return dar.GetBackOfCardCount();
        }

        /// <summary>
        /// 根据条件获取已发卡的数量
        /// </summary>
        /// <returns></returns>
        public int GetBackOfCardCountWhere(string query)
        {
            return dar.GetBackOfCardCountWhere(query);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }

        /// <summary>
        /// 获取已发卡人员信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<BackOfCardInfo> SelBackOfCardInfo(int pagesize, int startindex, string strquery)
        {
            IList<BackOfCardInfo> baclist = new List<BackOfCardInfo>();
            BackOfCardInfo bacinfo;
            DataSet ds = dar.SelBackOfCardInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                bacinfo = new BackOfCardInfo()
                {
                    PID = Convert.ToInt32(item["PID"]),
                    EmpNo = item["EmpNo"].ToString(),
                    deptName = item["deptName"].ToString(),
                    PersonTypeName = item["PersonTypeName"].ToString(),
                    PName = item["PName"].ToString(),
                    CardSerial = Convert.ToInt64(item["CardSerial"]),
                    Balance = Convert.ToDecimal(item["Balance"])
                };
                baclist.Add(bacinfo);
            }
            return baclist;
        }

        /// <summary>
        /// 根据编号获取一条人员信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public BackOfCardInfo GetBackOfCardInfoOne(string id)
        {
            dar = new DataAccessBackOfCard();
            DataSet ds = dar.GetBackOfCardInfoOne(id);
            BackOfCardInfo info = new BackOfCardInfo();
            info.PID = int.Parse(ds.Tables[0].Rows[0]["PID"].ToString());
            info.EmpNo = ds.Tables[0].Rows[0]["EmpNo"].ToString();
            info.deptName = ds.Tables[0].Rows[0]["deptName"].ToString();
            info.PersonTypeName = ds.Tables[0].Rows[0]["PersonTypeName"].ToString();
            info.PName = ds.Tables[0].Rows[0]["PName"].ToString();
            info.Dep_ID = int.Parse(ds.Tables[0].Rows[0]["Dep_ID"].ToString());
            if (ds.Tables[0].Rows[0]["CardSerial"].ToString() == "" || ds.Tables[0].Rows[0]["CardSerial"].ToString() == null)
            {
                info.CardSerial = 0;
            }
            else
            {
                info.CardSerial = Convert.ToInt64(ds.Tables[0].Rows[0]["CardSerial"].ToString());
            }
            if (ds.Tables[0].Rows[0]["Balance"].ToString() == "" || ds.Tables[0].Rows[0]["Balance"].ToString() == null)
            {
                info.Balance = 0;
            }
            else
            {
                info.Balance = Convert.ToDecimal(ds.Tables[0].Rows[0]["Balance"].ToString());
            }
            info.Status = ds.Tables[0].Rows[0]["Status"].ToString();
            info.WorkStatus = ds.Tables[0].Rows[0]["WorkStatus"].ToString();
            if (ds.Tables[0].Rows[0]["CardOptDeposit"].ToString() == "" || ds.Tables[0].Rows[0]["CardOptDeposit"].ToString() == null)
            {
                info.CardOptDeposit = 0;
            }
            else
            {
                info.CardOptDeposit = Convert.ToDecimal(ds.Tables[0].Rows[0]["CardOptDeposit"].ToString());
            }
            return info;
        }

        /// <summary>
        /// 保存（给人员退卡）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int SaveBackOfCard(BackOfCardInfo bac)
        {
            object[] objcar = new object[] { bac.EmpNo, bac.Balance, bac.CardOptDeposit, bac.OldMoney, bac.LOGOUTTYPE, bac.OperatorID };
            return dar.SaveBackOfCard(objcar);
        }
    }
}
